package com.link.base.base.salecategory.controller;

import com.link.base.base.salecategory.model.SaleCategory;
import com.link.base.base.salecategory.service.SaleCategoryService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.ServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: unknown
 * @date: unknown
 * @Comments 客户可售品类信息
 */
@Controller
@RequestMapping("/link/saleCategory")
public class SaleCategoryController extends BasicController<SaleCategory> {

    @Resource
    private SaleCategoryService saleCategoryService;

    @Override
    public BasicService<SaleCategory> getBasicService() throws Exception {
        return saleCategoryService;
    }

    /**
     * @param saleCategory
     * @return
     * @Auth HuangLJ
     * @Comments 通过客户Id查询可售品类
     */
    @RequestMapping(value = "/queryByAccntId", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryByAccntId(@JsonParam SaleCategory saleCategory) {

        Map<String, Object> result = new HashMap<String, Object>();
        Long accntId = saleCategory.getAccntId();
        try {
            if (accntId == null) {
                throw new ServiceException("PUBLIC-026");
            }
            List<SaleCategory> retList = saleCategoryService.queryByAccntId(saleCategory);
            result.put("success", true);
            result.put("saleCategory", retList);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
